// var i;
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_BankData = require("./AL_GAME_HUA_BankData");
// var p = cc._decorator;
// var f = p.ccclass;
// var d = p.property;
// var h =
//     (p.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.label_coin = null;
//             t.progress_bar = null;
//             t.anim = null;
//             t.red = null;
//             t.node_icon_coin = null;
//             t.particle = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.onLoad = function () {
//             var e = this;
//             AL_APP_SDK_MANAGER.on(
//                 AL_GAME_HUA_Define.GameEvent.ON_BANK_MONEY_CHANGE,
//                 function () {
//                     var t = AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian();
//                     e.progress_bar.progress = t / AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
//                     e.shuaxin_donghua();
//                 },
//                 this
//             );
//         };
//         t.prototype.onDestroy = function () {
//             AL_APP_SDK_MANAGER.off(this);
//         };
//         t.prototype.start = function () {
//             var e = AL_GAME_HUA_GameConst.GameConst.getInstance().pass_bank;
//             this.label_coin.string = "+" + e.toString();
//             this.shuaxin_donghua();
//             var t = AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian();
//             this.progress_bar.progress = t / AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
//             this.node_icon_coin.opacity = 0;
//             this.label_coin.node.opacity = 0;
//             AL_GAME_HUA_BankData.BankData.getInstance().tianjia_cunchu_de_jinqian(e);
//             this.node.on(
//                 cc.Node.EventType.TOUCH_END,
//                 function () {
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_yinhang_mianban();
//                 },
//                 this
//             );
//         };
//         t.prototype.bofang_donghua = function () {
//             var e = this;
//             cc.tween(this.label_coin.node)
//                 .to(0.2, {
//                     opacity: 255
//                 })
//                 .start();
//             cc.tween(this.node_icon_coin)
//                 .to(0.2, {
//                     opacity: 255
//                 })
//                 .delay(0.8)
//                 .call(function () {
//                     cc.tween(e.label_coin.node)
//                         .to(0.5, {
//                             opacity: 0
//                         })
//                         .start();
//                     cc.tween(e.node_icon_coin)
//                         .to(
//                             0.5,
//                             {
//                                 position: e.anim.node.position
//                             },
//                             {
//                                 easing: "sineIn"
//                             }
//                         )
//                         .call(function () {
//                             e.particle.active = !0;
//                             var t =
//                                 AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian() /
//                                 AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
//                             e.shuaxin_donghua();
//                             cc.tween(e.progress_bar)
//                                 .to(0.5, {
//                                     progress: t
//                                 })
//                                 .call(function () {})
//                                 .start();
//                         })
//                         .to(0.2, {
//                             opacity: 0
//                         })
//                         .start();
//                 })
//                 .start();
//         };
//         t.prototype.shuaxin_donghua = function () {
//             AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian() >=
//             AL_GAME_HUA_GameConst.GameConst.getInstance().money_valid
//                 ? (this.anim.setAnimation(0, "01-shouji", !0), (this.red.active = !0))
//                 : ((this.red.active = !1), this.anim.setAnimation(0, "01-shouji", !1));
//         };
//         __decorate([d(cc.Label)], t.prototype, "label_coin", void 0);
//         __decorate([d(cc.ProgressBar)], t.prototype, "progress_bar", void 0);
//         __decorate([d(sp.Skeleton)], t.prototype, "anim", void 0);
//         __decorate([d(cc.Node)], t.prototype, "red", void 0);
//         __decorate([d(cc.Node)], t.prototype, "node_icon_coin", void 0);
//         __decorate([d(cc.Node)], t.prototype, "particle", void 0);
//         return __decorate([f], t);
//     })(cc.Component));
// exports.default = h;


const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
const AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
const AL_GAME_HUA_BankData = require("./AL_GAME_HUA_BankData");

const { ccclass, property, menu } = cc._decorator;

/**
 * @class Enhances the component with specific bank and UI functionalities.
 * Component handles bank money changes and animates UI accordingly.
 */
@ccclass
class EnhancedBankComponent extends cc.Component {
    /** @type {cc.Label} */
    @property(cc.Label)
    label_coin = null;

    /** @type {cc.ProgressBar} */
    @property(cc.ProgressBar)
    progress_bar = null;

    /** @type {sp.Skeleton} */
    @property(sp.Skeleton)
    anim = null;

    /** @type {cc.Node} */
    @property(cc.Node)
    red = null;

    /** @type {cc.Node} */
    @property(cc.Node)
    node_icon_coin = null;

    /** @type {cc.Node} */
    @property(cc.Node)
    particle = null;

    /**
     * Lifecycle callback called when the component is loaded.
     * Sets up event listeners related to bank money changes.
     */
    onLoad() {
        AL_APP_SDK_MANAGER.on(
            AL_GAME_HUA_Define.GameEvent.ON_BANK_MONEY_CHANGE,
            () => {
                const savedMoney = AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian();
                this.progress_bar.progress = savedMoney / AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
                this.shuaxin_donghua();
            },
            this
        );
    }

    /**
     * Lifecycle callback called when the component is destroyed.
     * Removes any previously added listeners.
     */
    onDestroy() {
        AL_APP_SDK_MANAGER.off(this);
    }

    /**
     * Lifecycle callback called after all components are initialized.
     * Attaches UI behaviors and initializes some UI properties.
     */
    start() {
        const passBank = AL_GAME_HUA_GameConst.GameConst.getInstance().pass_bank;
        this.label_coin.string = "+" + passBank.toString();
        this.shuaxin_donghua();
        const savedMoney = AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian();
        this.progress_bar.progress = savedMoney / AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
        this.node_icon_coin.opacity = 0;
        this.label_coin.node.opacity = 0;
        AL_GAME_HUA_BankData.BankData.getInstance().tianjia_cunchu_de_jinqian(passBank);
        
        this.node.on(
            cc.Node.EventType.TOUCH_END,
            () => {
                AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_yinhang_mianban();
            },
            this
        );
    }

    /**
     * Initiates the animation sequence for updating the coin label, coin icon, and progress bar
     */
    bofang_donghua() {
        cc.tween(this.label_coin.node)
            .to(0.2, { opacity: 255 })
            .start();

        cc.tween(this.node_icon_coin)
            .to(0.2, { opacity: 255 })
            .delay(0.8)
            .call(() => {
                cc.tween(this.label_coin.node)
                    .to(0.5, { opacity: 0 })
                    .start();

                cc.tween(this.node_icon_coin)
                    .to(0.5, { 
                        position: this.anim.node.position 
                    }, 
                    { 
                        easing: "sineIn" 
                    })
                    .call(() => {
                        this.particle.active = true;
                        const current_progress = AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian() / AL_GAME_HUA_GameConst.GameConst.getInstance().money_max;
                        this.shuaxin_donghua();
                        cc.tween(this.progress_bar)
                            .to(0.5, { progress: current_progress })
                            .start();
                    })
                    .to(0.2, { opacity: 0 })
                    .start();
            })
            .start();
    }

    /**
     * Refreshes and updates the animation based on the current bank money.
     */
    shuaxin_donghua() {
        const savedMoney = AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian();
        const moneyValid = AL_GAME_HUA_GameConst.GameConst.getInstance().money_valid;

        if (savedMoney >= moneyValid) {
            this.anim.setAnimation(0, "01-shouji", true);
            this.red.active = true;
        } else {
            this.red.active = false;
            this.anim.setAnimation(0, "01-shouji", false);
        }
    }
}

exports.default = EnhancedBankComponent;